#pragma once

#include <stack>
#include <glibmm/refptr.h>

namespace CPreProc
{
  class IfSection;
  class IfGroupCondition;
  class Group;
  class TokenizerInput;
  class Tokenizer;
  class PreProcFile;

  /// \internal
  class FileParser
  {
  public:
    void                                  parse(Glib::RefPtr<TokenizerInput> tokenizer_doc);
    Glib::RefPtr<PreProcFile>             get_output() { return output_file; }

  private:
    void                                  parse_line(Tokenizer &tokenizer);
    void                                  parse_pragma(Tokenizer &tokenizer);
    
    void                                  begin_if_section(Glib::RefPtr<IfGroupCondition> condition);
    void                                  begin_elif_block(Glib::RefPtr<IfGroupCondition> condition);
    void                                  begin_else_block();
    void                                  end_if_section();

    Glib::RefPtr<TokenizerInput>            tokenizer_doc;
    Glib::RefPtr<PreProcFile>             output_file;

    struct IfSectionInfo
    {
      Glib::RefPtr<IfSection>   if_section;
      bool                      has_else_block;
    };

    std::stack<IfSectionInfo>             if_sections_stack;
    Glib::RefPtr<Group>                   cur_group;
  };
}

